<?php

/**
 * CelebrioNews default
 *
 * @copyright  Copyright (c) 2011 Celebrio Software
 * @package    CelebrioNews
 */
namespace ApplicationsModule\NewsModule;
use WebtopModule\BasePresenter;

class DefaultPresenter extends BasePresenter {

    public function startup() {
	parent::startup();
	header ( "Content-type:text/html; charset=utf-8" ); // TODO: poresit
	if ($this->isAjax()) {
	    $this->invalidateControl("celebrionewsappSnippet");
	}
    }

    public function renderDefault() {

    }

    public function renderIframe(){
	$this->template->iframeUrl = $this->link("Default:story", array('type'=>\htmlspecialchars($_GET["type"])));
    }

    public function renderStory() {
        $userLanguage = $this->getUser()->getIdentity()->data["language"];
	$newsReader = new NewsReader($userLanguage);
        try {
        switch($_GET["type"]){
	    case "topstories":
		$this->template->news = $newsReader->getTopStories();
		break;
	    case "world":
		$this->template->news = $newsReader->getWorld();
		break;
	    case "entertainmet":
		$this->template->news = $newsReader->getEntertainment();
		break;
	    case "sports":
		$this->template->news = $newsReader->getSports();
		break;
	    default:
		$this->template->news = $newsReader->getTopStories();
	}
        } catch(\InvalidStateException $e) {
            $this->template->error = $e->getMessage();
        }
    }

}